/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 2010-9-25, 16:12:41
 */

package finalsoft;

import Sql.Mysql;
import Sql.User;
import Table.TablePanel;
import Table.getAllInfo;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import java.io.File ;
import javax.imageio.ImageIO;

/**
 *
 * @author lq
 */
public class MainFrame extends javax.swing.JFrame {
    private TablePanel tb;
    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jControlPanel = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jLoginMenu = new javax.swing.JMenu();
        jLoginMenuItem = new javax.swing.JMenuItem();
        jUnregisterMenuItem = new javax.swing.JMenuItem();
        jExitMenuItem = new javax.swing.JMenuItem();
        jUserInfoMenu = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jUserRecordMenuItem = new javax.swing.JMenuItem();
        jStoreManageMenu = new javax.swing.JMenu();
        jGoodsInfoMenuItem = new javax.swing.JMenuItem();
        jSaleRecordMenuItem = new javax.swing.JMenuItem();
        jTaskManageMenuItem = new javax.swing.JMenuItem();
        jInManagerMenu = new javax.swing.JMenu();
        jGoodsInMenuItem = new javax.swing.JMenuItem();
        jOutManagerMenu = new javax.swing.JMenu();
        jGoodsOotMenuItem = new javax.swing.JMenuItem();
        jTogetherMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(finalsoft.FinalSoftApp.class).getContext().getResourceMap(MainFrame.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        jControlPanel.setName("jControlPanel"); // NOI18N
        try{
            image = ImageIO.read(new File(Sql.Config.index));

            welcome = new Welcome(image) ;
            jControlPanel.add(welcome) ;
            welcome.setSize(776, 482);
            welcome.setLocation(0, 0);
            welcome.setVisible(true);
            welcome.updateUI();
        }catch(Exception e){}

        javax.swing.GroupLayout jControlPanelLayout = new javax.swing.GroupLayout(jControlPanel);
        jControlPanel.setLayout(jControlPanelLayout);
        jControlPanelLayout.setHorizontalGroup(
            jControlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 776, Short.MAX_VALUE)
        );
        jControlPanelLayout.setVerticalGroup(
            jControlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 461, Short.MAX_VALUE)
        );

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jLoginMenu.setText(resourceMap.getString("jLoginMenu.text")); // NOI18N
        jLoginMenu.setName("jLoginMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(finalsoft.FinalSoftApp.class).getContext().getActionMap(MainFrame.class, this);
        jLoginMenuItem.setAction(actionMap.get("Login")); // NOI18N
        jLoginMenuItem.setText(resourceMap.getString("jLoginMenuItem.text")); // NOI18N
        jLoginMenuItem.setName("jLoginMenuItem"); // NOI18N
        jLoginMenu.add(jLoginMenuItem);

        jUnregisterMenuItem.setAction(actionMap.get("Unregister")); // NOI18N
        jUnregisterMenuItem.setText(resourceMap.getString("jUnregisterMenuItem.text")); // NOI18N
        jUnregisterMenuItem.setName("jUnregisterMenuItem"); // NOI18N
        jLoginMenu.add(jUnregisterMenuItem);

        jExitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        jExitMenuItem.setText(resourceMap.getString("jExitMenuItem.text")); // NOI18N
        jExitMenuItem.setActionCommand(resourceMap.getString("jExitMenuItem.actionCommand")); // NOI18N
        jExitMenuItem.setName("jExitMenuItem"); // NOI18N
        jLoginMenu.add(jExitMenuItem);

        jMenuBar1.add(jLoginMenu);

        jUserInfoMenu.setText(resourceMap.getString("jUserInfoMenu.text")); // NOI18N
        jUserInfoMenu.setEnabled(false);
        jUserInfoMenu.setName("jUserInfoMenu"); // NOI18N

        jMenuItem4.setAction(actionMap.get("getAllUsersInfo")); // NOI18N
        jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        jUserInfoMenu.add(jMenuItem4);

        jUserRecordMenuItem.setText(resourceMap.getString("jUserRecordMenuItem.text")); // NOI18N
        jUserRecordMenuItem.setName("jUserRecordMenuItem"); // NOI18N
        jUserInfoMenu.add(jUserRecordMenuItem);

        jMenuBar1.add(jUserInfoMenu);

        jStoreManageMenu.setText(resourceMap.getString("jStoreManageMenu.text")); // NOI18N
        jStoreManageMenu.setEnabled(false);
        jStoreManageMenu.setName("jStoreManageMenu"); // NOI18N

        jGoodsInfoMenuItem.setText(resourceMap.getString("jGoodsInfoMenuItem.text")); // NOI18N
        jGoodsInfoMenuItem.setName("jGoodsInfoMenuItem"); // NOI18N
        jStoreManageMenu.add(jGoodsInfoMenuItem);

        jSaleRecordMenuItem.setText(resourceMap.getString("jSaleRecordMenuItem.text")); // NOI18N
        jSaleRecordMenuItem.setName("jSaleRecordMenuItem"); // NOI18N
        jStoreManageMenu.add(jSaleRecordMenuItem);

        jTaskManageMenuItem.setText(resourceMap.getString("jTaskManageMenuItem.text")); // NOI18N
        jTaskManageMenuItem.setName("jTaskManageMenuItem"); // NOI18N
        jStoreManageMenu.add(jTaskManageMenuItem);

        jMenuBar1.add(jStoreManageMenu);

        jInManagerMenu.setText(resourceMap.getString("jInManagerMenu.text")); // NOI18N
        jInManagerMenu.setEnabled(false);
        jInManagerMenu.setName("jInManagerMenu"); // NOI18N

        jGoodsInMenuItem.setText(resourceMap.getString("jGoodsInMenuItem.text")); // NOI18N
        jGoodsInMenuItem.setName("jGoodsInMenuItem"); // NOI18N
        jInManagerMenu.add(jGoodsInMenuItem);

        jMenuBar1.add(jInManagerMenu);

        jOutManagerMenu.setText(resourceMap.getString("jOutManagerMenu.text")); // NOI18N
        jOutManagerMenu.setEnabled(false);
        jOutManagerMenu.setName("jOutManagerMenu"); // NOI18N

        jGoodsOotMenuItem.setText(resourceMap.getString("jGoodsOotMenuItem.text")); // NOI18N
        jGoodsOotMenuItem.setName("jGoodsOotMenuItem"); // NOI18N
        jOutManagerMenu.add(jGoodsOotMenuItem);

        jMenuBar1.add(jOutManagerMenu);

        jTogetherMenu.setText(resourceMap.getString("jTogetherMenu.text")); // NOI18N
        jTogetherMenu.setEnabled(false);
        jTogetherMenu.setName("jTogetherMenu"); // NOI18N

        jMenuItem1.setAction(actionMap.get("ModifyInfo")); // NOI18N
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem1MouseClicked(evt);
            }
        });
        jTogetherMenu.add(jMenuItem1);

        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jTogetherMenu.add(jMenuItem2);

        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jTogetherMenu.add(jMenuItem3);

        jMenuBar1.add(jTogetherMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jControlPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jControlPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MouseClicked
        // TODO add your handling code here:
      
    }//GEN-LAST:event_jMenuItem1MouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    @Action
    public void Login() {
        try {
            image = ImageIO.read(new File(Sql.Config.index));
            LoginPanel lp = new LoginPanel(); //新建登陆面板
            welcome.setVisible(false);
            lp.setSize(776, 482); //设置其大小
            lp.setLocation(0, 0); //设置其位置
            lp.setVisible(true); //将其设为可见
            jControlPanel.add(lp); //把登陆面板加载到主面板上
            lp.repaint();
            lp.updateUI(); //更新控件 如果不更新  只有改变长提的大小后控件才能显示出来
            jLoginMenuItem.setEnabled(false);
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    @Action
    public void Unregister() {
        jControlPanel.removeAll();//当点击注销菜单项的时候要先将主面板上的所有库面板先移除
        jLoginMenuItem.setEnabled(false) ;
        jUserInfoMenu.setEnabled(false) ;
        jOutManagerMenu.setEnabled(false);
        jInManagerMenu.setEnabled(false);
        jStoreManageMenu.setEnabled(false);
        jTogetherMenu.setEnabled(false);
        
        Login();
    }

    @Action
    public void getAllUsersInfo() {
//        javax.swing.JPanel jp = new javax.swing.JPanel();
//        jp.setSize(776, 482);//设置其大小
//        jp.setLocation(0, 0);//设置其位置
//        jp.setVisible(true);//将其设为可见
//
//        /**************************************/
//        // 下面要加 用户信息表
//        try{
//
//        Sql.Mysql mysql = new Sql.Mysql();
//        Object [][] obj = Methods.getYouWang(mysql.getAllUserV2(),0,1,2,5,7,8,9,10);
////        String[] titles = {"编号","名字","性别","密码","级别号","级别","上次登录时间","地址","电子邮件","电话","其他信息",};
//        String[] titles = {"编号","名字","性别","级别","地址","电子邮件","电话","其他信息",};
//
//        DefaultTable dt = new DefaultTable(titles,obj);
//        javax.swing.JTable jt = new javax.swing.JTable(dt);
//        javax.swing.JScrollPane jsp = new javax.swing.JScrollPane(jt);
//        jp.add(jsp);
//        }catch(Exception e){}
//        /**************************************/
//
//
//        jControlPanel.removeAll();
//        jControlPanel.add(jp);
//        jp.updateUI();

        try {
            image = ImageIO.read(new File(Sql.Config.yuangong));
      

            tb = new  TablePanel( new User() , image);
        } catch (Exception e) {}
       // this.add(tb);
        tb.setVisible(true);
        tb.setSize(776, 479);
        tb.setLocation(0, 0);
        jControlPanel.removeAll();
        jControlPanel.add(tb);
        tb.updateUI();
    }

    @Action
    public void ModifyInfo() {
        try{
        image = ImageIO.read(new File(Sql.Config.userInfoChange));
        //image = ImageIO.read(new File("resources.busyicons/userInfoChange.jpg"));
        ModifyInfo  modifyInfo = new ModifyInfo(image);//要想给JPanel加配镜图片 就要重写构造函数 和paintComponent方法

        modifyInfo.setVisible(false);
        jControlPanel.removeAll();
        modifyInfo.setSize(776, 482);
        modifyInfo.setLocation(0, 0);

        jControlPanel.add(modifyInfo);
        modifyInfo.setVisible(true);        
        modifyInfo.updateUI();
         }catch(Exception e){}
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jControlPanel;
    private javax.swing.JMenuItem jExitMenuItem;
    private javax.swing.JMenuItem jGoodsInMenuItem;
    private javax.swing.JMenuItem jGoodsInfoMenuItem;
    private javax.swing.JMenuItem jGoodsOotMenuItem;
    private javax.swing.JMenu jInManagerMenu;
    private javax.swing.JMenu jLoginMenu;
    private javax.swing.JMenuItem jLoginMenuItem;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenu jOutManagerMenu;
    private javax.swing.JMenuItem jSaleRecordMenuItem;
    private javax.swing.JMenu jStoreManageMenu;
    private javax.swing.JMenuItem jTaskManageMenuItem;
    private javax.swing.JMenu jTogetherMenu;
    private javax.swing.JMenuItem jUnregisterMenuItem;
    private javax.swing.JMenu jUserInfoMenu;
    private javax.swing.JMenuItem jUserRecordMenuItem;
    // End of variables declaration//GEN-END:variables
    private BufferedImage image ;
    private Welcome welcome ;
   
}
